﻿using Abcd.Customer.Application.Contracts;
using Abcd.Order.Application.Contracts.PurchaseOrder;
using Abcd.Order.Domain.Shared.PurchaseOrder;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Services;

namespace Abcd.Order.Application.PurchaseOrder
{
    [RemoteService]
    [Route("purchase-order")]
    public class PurchaseOrderService : ApplicationService, IPurchaseOrderService
    {
        #region DI

        private readonly IPurchaseOrderManager _purchaseOrderManager;
        private readonly ICustomerService _customerService;


        public PurchaseOrderService(
            IPurchaseOrderManager purchaseOrderManager,
            ICustomerService customerService)
        {
            _purchaseOrderManager = purchaseOrderManager;
            _customerService = customerService;
        }

        #endregion

        [HttpPost("submit")]
        public async Task<string> SubmitOrderAsync(int commodityId, int quantity)
        {
            var customerId = 3;
            await _purchaseOrderManager.SubmitAsync(commodityId, quantity);
            var customer = await _customerService.TestGetCustomerAsync(customerId);
            return $"{customer}下单成功：商品（{commodityId}）数量：{quantity}";
        }
    }
}
